package com.woniuxy.oa.dao;

import com.woniuxy.oa.dao.provider.DeptProvider;
import com.woniuxy.oa.entity.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Auther: M
 * @Date: 2019/12/24 17:21
 * @Description:部门DAO
 */
public interface DeptDAO {
    /*
     *
     * @Description //增加新部门
     * @Date 2019/12/24 17:25
     * @param dept部门
     **/
    @Insert("insert into oa_dept values(#{id},#{deptName},#{pid},#{empId})")
    public void add(Dept dept);
    /*
     *
     * @Description //根据条件查询所有部门
     * @Date 2019/12/24 17:29
     * @param
     *@return java.util.List<com.woniuxy.oa.entity.Dept>
     **/
    @SelectProvider(type = DeptProvider.class, method = "getAllDeptByCondition")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(id = true,column = "empId",property = "emp.id"),
            @Result(column = "empName",property = "emp.name"),
            @Result(column = "phonenum",property = "emp.phoneNum"),
            @Result(column = "email",property = "emp.email")
    })
    public List<Dept> getAllDeptByCondition(Dept dept);

    /*
     *
     * @Description //根据部门名称查询部门
     * @Date 2019/12/24 17:47
     * @param name
     *@return int
     **/
    @Select("select count(*) from oa_dept where deptname=#{deptName}")
    public int getDeptCountByName(String name);

    /*
     *
     * @Description //物理删除
     * @Date 2019/12/25 10:21
     * @param id
     *@return void
     **/
    @Delete("delete from oa_dept where id=#{id}")
    public void del(String id);
    /*
     *
     * @Description //根据id逻辑删除
     * @Date 2019/12/25 10:25
     * @param
     *@return void
     **/
    @Update("update oa_dept set status='n' where id=#{id}" )
    public void delete(String id);
    /*
     *
     * @Description //根据id查询部门
     * @Date 2019/12/26 11:14
     * @param
     *@return java.util.List<com.woniuxy.oa.entity.Dept>
     **/
    @Select("SELECT * FROM oa_dept d LEFT JOIN oa_emp e ON d.empid=e.id WHERE d.id=#{id}")
    @Results({
            @Result(id = true,column = "empId",property = "emp.id"),
            @Result(column = "empname",property = "emp.name"),
            @Result(column = "empno",property = "emp.empNo"),
            @Result(column = "phoneNum",property = "emp.phoneNum"),
            @Result(column = "gender",property = "emp.gender"),
            @Result(column = "avatar",property = "emp.avatar"),
            @Result(column = "entryTime",property = "emp.entryTime"),

    })
    public Dept getDeptById(String id);

    /*
     *
     * @Description //修改部门
     * @Date 2019/12/27 17:34
     * @param
     *@return void
     **/
    @Select("UPDATE oa_dept SET empid=#{emp.id}")
    public void update(Dept dept);

    /*
     *
     * @Description //查询所有部门
     * @Date 2019/12/27 17:34
     * @param
     *@return void
     **/
    @Select("select *from oa_dept ")
    public List<Dept> getAll();

    /**
     * @Description //根据部门名称查询部门
     * @Date 2019/12/31 9:59
     * @param name
     *@return com.woniuxy.oa.entity.Dept
     **/
    @Select("select * from oa_dept where deptname=#{deptName}")
    public Dept getDeptByName(String name);
}